/*
 * Copyright (c) 2025 GuoKaiHong (Shenzhen) Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import { initCallback } from "./i_printer_service";
import { selfCheckCallback } from "./i_printer_service";
import { printStringCallback } from "./i_printer_service";
import { printChinaStringCallback } from "./i_printer_service";
import { printCutPaperCallback } from "./i_printer_service";
import { printChargeRowCallback } from "./i_printer_service";
import { setAlignmentCallback } from "./i_printer_service";
import { setSizeTextCallback } from "./i_printer_service";
import { setBoldCallback } from "./i_printer_service";
import { setSizeCharCallback } from "./i_printer_service";
import { setSizeChineseCallback } from "./i_printer_service";
import { printFeedDotCallback } from "./i_printer_service";
import { setCloseCallback } from "./i_printer_service";
import { setCleanCallback } from "./i_printer_service";
import { getStatusCallback } from "./i_printer_service";
import { printQrcodeCallback } from "./i_printer_service";
import { print1DBarCallback } from "./i_printer_service";
import { printDiskImgFileCallback } from "./i_printer_service";
import { printDiskBmpFileCallback } from "./i_printer_service";
import IPrinterService from "./i_printer_service";
import rpc from "@ohos.rpc";

export default class PrinterServiceStub extends rpc.RemoteObject implements IPrinterService {
  constructor(des: string) {
    super(des);
  }

  onRemoteRequest(code: number, data, reply, option): boolean {
    console.log("onRemoteRequest called, code = " + code);
    switch (code) {
      case PrinterServiceStub.COMMAND_INIT: {
        let _deviceId = data.readInt();
        this.init(_deviceId, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SELF_CHECK: {
        this.selfCheck((errCode) => {
          reply.writeInt(errCode);
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_STRING: {
        let _strData = data.readString();
        let _iImme = data.readInt();
        this.printString(_strData, _iImme, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_CHINA_STRING: {
        let _strData = data.readString();
        let _iImme = data.readInt();
        this.printChinaString(_strData, _iImme, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_CUT_PAPER: {
        let _iMode = data.readInt();
        this.printCutPaper(_iMode, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_CHARGE_ROW: {
        this.printChargeRow((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_ALIGNMENT: {
        let _iAlignment = data.readInt();
        this.setAlignment(_iAlignment, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_SIZE_TEXT: {
        let _iHeight = data.readInt();
        let _iWidth = data.readInt();
        this.setSizeText(_iHeight, _iWidth, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_BOLD: {
        let _iBold = data.readInt();
        this.setBold(_iBold, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_SIZE_CHAR: {
        let _iHeight = data.readInt();
        let _iWidth = data.readInt();
        let _iUnderline = data.readInt();
        let _iAsciiType = data.readInt();
        this.setSizeChar(_iHeight, _iWidth, _iUnderline, _iAsciiType, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_SIZE_CHINESE: {
        let _iHeight = data.readInt();
        let _iWidth = data.readInt();
        let _iUnderline = data.readInt();
        let _iChineseType = data.readInt();
        this.setSizeChinese(_iHeight, _iWidth, _iUnderline, _iChineseType, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_FEED_DOT: {
        let _iNumber = data.readInt();
        this.printFeedDot(_iNumber, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_CLOSE: {
        this.setClose((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_SET_CLEAN: {
        this.setClean((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_GET_STATUS: {
        this.getStatus((errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_QRCODE: {
        let _strData = data.readString();
        let _iLMargin = data.readInt();
        let _iMSide = data.readInt();
        let _iRound = data.readInt();
        this.printQrcode(_strData, _iLMargin, _iMSide, _iRound, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT1_D_BAR: {
        let _iWidth = data.readInt();
        let _iHeight = data.readInt();
        let _iHriSize = data.readInt();
        let _iHriSeat = data.readInt();
        let _iCodeType = data.readInt();
        let _strData = data.readString();
        this.print1DBar(_iWidth, _iHeight, _iHriSize, _iHriSeat, _iCodeType, _strData, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_DISK_IMG_FILE: {
        let _strPath = data.readString();
        this.printDiskImgFile(_strPath, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      case PrinterServiceStub.COMMAND_PRINT_DISK_BMP_FILE: {
        let _strPath = data.readString();
        this.printDiskBmpFile(_strPath, (errCode, returnValue) => {
          reply.writeInt(errCode);
          if (errCode == 0) {
            reply.writeInt(returnValue);
          }
        });
        return true;
      }
      default: {
        console.log("invalid request code" + code);
        break;
      }
    }
    return false;
  }

  init(deviceId: number, callback: initCallback): void {
  }

  selfCheck(callback: selfCheckCallback): void {
  }

  printString(strData: string, iImme: number, callback: printStringCallback): void {
  }

  printChinaString(strData: string, iImme: number, callback: printChinaStringCallback): void {
  }

  printCutPaper(iMode: number, callback: printCutPaperCallback): void {
  }

  printChargeRow(callback: printChargeRowCallback): void {
  }

  setAlignment(iAlignment: number, callback: setAlignmentCallback): void {
  }

  setSizeText(iHeight: number, iWidth: number, callback: setSizeTextCallback): void {
  }

  setBold(iBold: number, callback: setBoldCallback): void {
  }

  setSizeChar(iHeight: number, iWidth: number, iUnderline: number, iAsciiType: number,
    callback: setSizeCharCallback): void {
  }

  setSizeChinese(iHeight: number, iWidth: number, iUnderline: number, iChineseType: number,
    callback: setSizeChineseCallback): void {
  }

  printFeedDot(iNumber: number, callback: printFeedDotCallback): void {
  }

  setClose(callback: setCloseCallback): void {
  }

  setClean(callback: setCleanCallback): void {
  }

  getStatus(callback: getStatusCallback): void {
  }

  printQrcode(strData: string, iLMargin: number, iMSide: number, iRound: number, callback: printQrcodeCallback): void {
  }

  print1DBar(iWidth: number, iHeight: number, iHriSize: number, iHriSeat: number, iCodeType: number, strData: string,
    callback: print1DBarCallback): void {
  }

  printDiskImgFile(strPath: string, callback: printDiskImgFileCallback): void {
  }

  printDiskBmpFile(strPath: string, callback: printDiskBmpFileCallback): void {
  }

  static readonly COMMAND_INIT = 1;
  static readonly COMMAND_SELF_CHECK = 2;
  static readonly COMMAND_PRINT_STRING = 3;
  static readonly COMMAND_PRINT_CHINA_STRING = 4;
  static readonly COMMAND_PRINT_CUT_PAPER = 5;
  static readonly COMMAND_PRINT_CHARGE_ROW = 6;
  static readonly COMMAND_SET_ALIGNMENT = 7;
  static readonly COMMAND_SET_SIZE_TEXT = 8;
  static readonly COMMAND_SET_BOLD = 9;
  static readonly COMMAND_SET_SIZE_CHAR = 10;
  static readonly COMMAND_SET_SIZE_CHINESE = 11;
  static readonly COMMAND_PRINT_FEED_DOT = 12;
  static readonly COMMAND_SET_CLOSE = 13;
  static readonly COMMAND_SET_CLEAN = 14;
  static readonly COMMAND_GET_STATUS = 15;
  static readonly COMMAND_PRINT_QRCODE = 16;
  static readonly COMMAND_PRINT1_D_BAR = 17;
  static readonly COMMAND_PRINT_DISK_IMG_FILE = 18;
  static readonly COMMAND_PRINT_DISK_BMP_FILE = 19;
}

